package com.wpre.lotterysystem.dao.mapper;

import com.wpre.lotterysystem.dao.dataobject.PrizeDO;
import jakarta.validation.constraints.NotNull;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-12-20
 * Time: 19:20
 */

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize(name,image_url,price,description) " +
            " values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
//拿到数据库中的对应的id,塞回给PrizeDO的id
    int insert(PrizeDO prizeDO);

    //查询奖品总量
    @Select("select count(*) from prize")
    int count();

    //奖品列表
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

    //查询数据库中所有的存在的奖品的id
    @Select("<script>" +
            " select id from prize" +
            " where id in " +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> id);


    @Select("<script>" +
            " select * from prize" +
            " where id in " +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> id);


    @Select("select * from prize where id = #{id}")
    PrizeDO SelectById(@Param("id") Long prizeId);
}
